
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
electron-localshortcut
Advanced tools
register/unregister a keyboard shortcut locally to a BrowserWindow instance, without using a Menu
A module to register/unregister a keyboard shortcut locally to a BrowserWindow instance, without using a Menu.
This is built to circumvent this Electron issue.
Note: Since this module internally use global-shortcut
native module, you should not use it until the ready
event of the app module is emitted. See electron docs.
npm install --save electron-localshortcut
const electronLocalshortcut = require('electron-localshortcut');
const BrowserWindow = require('browser-window');
const win = new BrowserWindow();
win.loadUrl('https://github.com');
win.show();
electronLocalshortcut.register(win, 'Ctrl+A', () => {
console.log('You pressed ctrl & A');
});
electronLocalshortcut.register(win, 'Ctrl+B', () => {
console.log('You pressed ctrl & B');
});
console.log(
electronLocalshortcut.isRegistered(win, 'Ctrl+A')
); // true
electronLocalshortcut.unregister(win, 'Ctrl+A');
electronLocalshortcut.unregisterAll(win);
The electron-localshortcut
module has following methods:
register(window, accelerator, callback)
window
BrowserWindow instanceaccelerator
Acceleratorcallback
FunctionRegisters a shortcut of accelerator
on the window
BrowserWindow instance. The callback
is called when the registered shortcut is pressed by the user, only if window
is focused.
isRegistered(window, accelerator)
window
BrowserWindow instanceaccelerator
AcceleratorReturns true
or false
depending on whether the shortcut accelerator
is
registered on window
.
unregister(window, accelerator)
window
BrowserWindow instanceaccelerator
AcceleratorUnregisters the shortcut of accelerator
registered on the BrowserWindow instance.
unregisterAll(window)
window
BrowserWindow instanceUnregisters all of the shortcuts registered on the BrowserWindow instance.
This set of methods allow you to manage shortcuts that work on any window of your app. They are active only when a window in the app is focused.
They differ from native global-shortcuts because they doesn't interfere with other apps running on the same machine.
register(accelerator, callback)
accelerator
Acceleratorcallback
FunctionRegisters a shortcut of accelerator
on any focused BrowserWindow instance. The callback
is called when the registered shortcut is pressed by the user, only if a BrowserWindow is focused.
isRegistered(accelerator)
accelerator
AcceleratorReturns true
or false
depending on whether the shortcut accelerator
is registered on all focused instances. If you registered the shortcut on a particular instance, this method
return false.
unregister(accelerator)
accelerator
AcceleratorUnregisters the shortcut of accelerator
registered on all focused instances. This method does not unregister any shortcut you
registered on a particular window instance.
unregisterAll()
Unregisters all of the shortcuts registered on any focused BrowserWindow instance. This method does not unregister any shortcut you registered on a particular window instance.
The MIT License (MIT)
Copyright (c) 2015 Andrea Parodi
FAQs
register/unregister a keyboard shortcut locally to a BrowserWindow instance, without using a Menu
The npm package electron-localshortcut receives a total of 22,952 weekly downloads. As such, electron-localshortcut popularity was classified as popular.
We found that electron-localshortcut demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.